package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.basebean.BaseRespVo;
import com.cskaoyan.bean.zhao_order_bean.BasePageData;
import com.cskaoyan.service.AfterSaleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <h3>market</h3>
 *
 * @author:Zhao
 * @date:2021-10-19 20:49:42
 * @description:
 */
@RestController
@RequestMapping("admin/aftersale")

public class AfterSaleController {
    @Autowired
    AfterSaleService aftersaleService;

    //请求参数：（非json）
    //page: 1
    //limit: 20
    //status: (售后状态，1为待审核，2为待退款，为空即查询全部)
    //sort: add_time
    //order: desc

    @RequiresPermissions(value = "admin:aftersale:list")
    @RequestMapping("list")
    public BaseRespVo list(String aftersaleSn, Integer orderId,
                           Short status, BaseParam param) {

        BasePageData data = aftersaleService.query
                (aftersaleSn, orderId, status, param);

        return BaseRespVo.ok(data);
    }


    //退款（误：将售后记录进行逻辑删除。。。根据数据库说明，应将状态码改为3）
    @RequiresPermissions(value = "admin:aftersale:refund")
    @RequestMapping("refund")
    public BaseRespVo list(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");

        aftersaleService.refund(orderId);

        return BaseRespVo.ok();
    }

    //通过（售后状态改为待退款）
    @RequiresPermissions(value = "admin:aftersale:recept")
    @RequestMapping("recept")
    public BaseRespVo recept(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");

        aftersaleService.recept(orderId);

        return BaseRespVo.ok();
    }

    //拒绝，状态码改为4
    @RequiresPermissions(value = "admin:aftersale:reject")
    @RequestMapping("reject")
    public BaseRespVo reject(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");

        aftersaleService.reject(orderId);

        return BaseRespVo.ok();
    }

    //批量通过
    @RequiresPermissions(value = "admin:aftersale:batch-recept")
    @RequestMapping("batch-recept")
    public BaseRespVo batchRecept(@RequestBody Map map) {
        List<Integer> ids = (List) map.get("ids");//能取到数组参数

        aftersaleService.batchRecept(ids);

        return BaseRespVo.ok();
    }

    //批量拒绝
    @RequiresPermissions(value = "admin:aftersale:batch-reject")
    @RequestMapping("batch-reject")
    public BaseRespVo batchReject(@RequestBody Map map) {
        List<Integer> ids = (List) map.get("ids");

        aftersaleService.batchReject(ids);

        return BaseRespVo.ok();
    }

}
